package swg.shape;

import java.util.ArrayList;

public class Circle implements IswgShape

{
	  @Override
	public String toString()
	{
		return "Circle [cx=" + cx + ", cy=" + cy + ", fill=" + fill + ", r=" + r + ", stroke=" + stroke + ", strokeWidth=" + strokeWidth + "]";
	}


	  protected int cx=0;
	  protected int cy=0;
	  protected int r=0;
	  protected int strokeWidth=0;
	  protected String stroke="";
	  protected String fill="";
	  

		public Circle(int cx, int cy, int r, int strokeWidth, String stroke, String fill)
		{
			super();
			this.cx = cx;
			this.cy = cy;
			this.r = r;
			this.strokeWidth = strokeWidth;
			this.stroke = stroke;
			this.fill = fill;
		}

		public Circle(int cx, int cy, int r)
		{
			super();
			this.cx = cx;
			this.cy = cy;
			this.r = r;
		}


	public int getCx()
	{
		return cx;
	}


	public void setCx(int cx)
	{
		this.cx = cx;
	}


	public int getCy()
	{
		return cy;
	}


	public void setCy(int cy)
	{
		this.cy = cy;
	}


	public int getR()
	{
		return r;
	}


	public void setR(int r)
	{
		this.r = r;
	}


	public int getStrokeWidth()
	{
		return strokeWidth;
	}


	public void setStrokeWidth(int strokeWidth)
	{
		this.strokeWidth = strokeWidth;
	}


	public String getStroke()
	{
		return stroke;
	}


	public void setStroke(String stroke)
	{
		this.stroke = stroke;
	}


	public String getFill()
	{
		return fill;
	}


	public void setFill(String fill)
	{
		this.fill = fill;
	}


	@Override
	public String getSWGCode()
	{
		String swg ="<circle cx=\""+cx+"\" cy=\""+cy+"\" r=\""+r+"\" " +
						(stroke.equalsIgnoreCase("")?"":"stroke=\""+stroke+"\" " )+
						(strokeWidth==0?"":"stroke-width=\""+strokeWidth+"\" ") +
						(fill.equalsIgnoreCase("")?"":"fill=\""+fill+"\" ") +
							" />";
		return swg;
	}

	public boolean collide(ArrayList<IswgShape> shapes)
	{
		if(shapes.size()==0)
			return false;
		for(IswgShape s: shapes){
			double dd =Math.sqrt((s.getX()-cx)*(s.getX()-cx)+(s.getY()-cy)*(s.getY()-cy));
			double rr =(s.getR()+r);
			if (dd<rr){
				return true;
			}

			//System.out.println("d= "+dd +"  rr="+rr);
		}
		return false;
	}

	@Override
	public int getX()
	{
		return cx;
	}

	@Override
	public int getY()
	{
		return cy;
	}

	public boolean inFrame(int xMin, int xMAX, int yMin, int yMAX)
	{
		
		if(
				(cx-r>xMAX && cx-r<xMin) &&
				(cx+r>xMAX && cx+r<xMin) &&
				(cy-r>yMAX && cy-r<yMin) &&
				(cy+r>yMAX && cy+r<yMin) ){
			return true;
		}
		return false;
	}
}
